//
//  ASMyMessageVC.m
//  AttendenceSys
//
//  Created by 窦芳俊 on 16/1/24.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "ASMyMessageVC.h"
#import "ASMyMessageCell.h"

@interface ASMyMessageVC ()

@property (nonatomic, strong) UITableView *myMsgTableView;
@property (nonatomic, strong) NSMutableArray *myMsgArray;

@end

@implementation ASMyMessageVC

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setLeftButtonWithImageName:@"ic_back" bgImageName:nil];
    self.strNavTitle = @"我的消息";
    
    [self fetchMyMessage];

    [self initUI];
}

- (void)initUI
{
    UIImageView* bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.image = [UIImage imageNamed:@"bg_personal"];
    bgView.userInteractionEnabled = YES;
    [self.view addSubview:bgView];
    
    // myMsgTableView
    _myMsgTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _myMsgTableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    _myMsgTableView.delegate = self;
    _myMsgTableView.dataSource = self;
    _myMsgTableView.backgroundColor = [UIColor whiteColor];
    _myMsgTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_myMsgTableView registerClass:[ASMyMessageCell class] forCellReuseIdentifier:NSStringFromClass([ASMyMessageCell class])];
    [bgView addSubview:_myMsgTableView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)fetchMyMessage
{
    //消息接口 http://121.42.185.124:8080/LawSchool/getStudentDutyList.action?userCode=xiaohu&page=1&rowNum=10&userType=1(1表示老师2表示学生)
    
    NSString* refer = @"getStudentDutyList.action?";
    NSString* prefix = kASHttpUrl(refer);
    NSString* userCode = [ASAppDelegate sharedAppDelegate].userInfo.userCode;
    NSString* userType = [ASAppDelegate sharedAppDelegate].userInfo.sourceTypeId;
    NSString* totalUrl = [NSString stringWithFormat:@"%@userCode=%@&page=1&rowNum=10&userType=%@", prefix, userCode, userType];
    
    [SVProgressHUD showWithStatus:@"获取中..." maskType:SVProgressHUDMaskTypeClear];
    ASNetworkEngine *networkingEngine = [ASNetworkEngine sharedInstance];
    [networkingEngine GET:totalUrl parameters:nil success:^(id responseObject) {
        NSDictionary* jsonRsp = (NSDictionary *)responseObject;
        if (isSuccessRsp(jsonRsp))
        {
            NSDictionary* data = [jsonRsp objectForKey:kASJsonData];
            if ([data count] > 0)
            {
                data = [data processDictionaryIsNSNull:data];
            }
            
            [SVProgressHUD dismiss];
        }
        else
        {
            [SVProgressHUD showErrorWithStatus:errorMsgRsp(jsonRsp)];
        }
    } failure:^(NSError *error) {
        //[SVProgressHUD showErrorWithStatus:error.description];
        [SVProgressHUD showErrorWithStatus:@"网络异常，请稍后再试"];
    }];
}

- (void)parseMyMessageInfo:(NSDictionary *)rsp
{
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0f;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_myMsgArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ASMyMessageCell class])];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}


@end






